package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class TimeAspect {
    @Around("execution(* com.itheima.service.*.get*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable{
        //记录开始时间
        Long begin = System.currentTimeMillis();
        //执行原来的方法
        Object result = pjp.proceed();
        //记录结束时间
        Long end = System.currentTimeMillis();
        //计算用时
        log.info(pjp.getSignature()+"执行耗时：{}毫秒",end-begin);
        return result;
    }
}
